package com.example.lin.zyfypt_327ljd.activity;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Switch;
import android.widget.Toast;

import com.example.lin.zyfypt_327ljd.R;
import com.example.lin.zyfypt_327ljd.bean.LoginBean;
import com.example.lin.zyfypt_327ljd.iface.RegisterListener;
import com.example.lin.zyfypt_327ljd.model.RegisterModel;
public class RegisterActivity extends AppCompatActivity implements View.OnClickListener {
    private Button btn1,btn3;
    private EditText name, pwd, pwdr, age,tel;

    RegisterListener registerListener = new RegisterListener() {
        @Override
        public void onResponse(LoginBean loginBean) {
            if(loginBean.equals("1")){
                System.out.println("result:"+loginBean);
                //finish();
        }
    }
        @Override
        public void onFail(String msg) {
            Toast.makeText(RegisterActivity.this, msg, Toast.LENGTH_SHORT).show();
        }
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        init();
    }
    private void init() {
        name = (EditText)findViewById(R.id.editText1);
        pwd = (EditText)findViewById(R.id.editText2);
        pwdr = (EditText)findViewById(R.id.editText3);
        age = (EditText)findViewById(R.id.editText4);
        tel = (EditText)findViewById(R.id.editText5);
        btn1 = (Button)findViewById(R.id.button1);
        btn3 = (Button)findViewById(R.id.button3);
        btn1.setOnClickListener(this);
        btn3.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId())
        {
        case R.id.button1:
        RegisterModel registerModel = new RegisterModel();
        registerModel.getResult(name.getText().toString(), pwd.getText().toString(), tel.getText().toString(), registerListener);
        Toast.makeText(this, "注册成功", Toast.LENGTH_SHORT).show();
        break;
        case R.id.button3:
            Intent intent=new Intent(RegisterActivity.this,LoginActivity.class);
            startActivity(intent);
            break;
        }
    }
}
